package com.toumy.controller;

import com.toumy.domain.Code;
import com.toumy.domain.Result;
import com.toumy.service.ImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;

@RestController
@RequestMapping("/img")
public class ImageController {
    @Autowired
    private ImgService upload;

    @PostMapping("/{id}")
    public Result uploadImg(@RequestParam("files") MultipartFile[] files,@PathVariable int id) throws IOException {
        if (files.length == 0)
            return new Result(Code.ADD_F,null,"图片加载失败");

        boolean flag = upload.upload(id,files);

        return flag?new Result(Code.ADD_S,null,"上传成功"):new Result(Code.ADD_F,null,"上传失败");
    }
}
